#include "CEnemyType1.h"
#include "MainLayer.h"

CEnemyType1::CEnemyType1(CEnemyParams enemyParams) : CEnemy(enemyParams)
{
}

void
CEnemyType1::createBoxBodyForSize(CEnemyParams::EEnemySize size)
{
	CEnemy::createBoxBody();

	switch(size)
	{
	case CEnemyParams::size1:
		createBoxBodySize1();
		break;
	case CEnemyParams::size2:
		createBoxBodySize2();
		break;
	case CEnemyParams::size3:
		createBoxBodySize3();
		break;
	case CEnemyParams::size4:
		createBoxBodySize4();
		break;
	default:
		break;
	}
}

void
CEnemyType1::createBoxBodySize1()
{
	b2PolygonShape spriteShape;
	int num = 6;
	b2Vec2 verts[] = {
			b2Vec2(-36.3440f / P2M, -11.6651f / P2M),
			b2Vec2(-7.8776f / P2M, -16.6887f / P2M),
			b2Vec2(33.6496f / P2M, -13.6744f / P2M),
			b2Vec2(39.0080f / P2M, -4.2974f / P2M),
			b2Vec2(23.6024f / P2M, 14.7920f / P2M),
			b2Vec2(-18.2600f / P2M, 15.4615f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}

void
CEnemyType1::createBoxBodySize2()
{
	b2PolygonShape spriteShape;
	int num = 6;
	b2Vec2 verts[] = {
			b2Vec2(-45.7210f / P2M, -14.3445f / P2M),
			b2Vec2(-8.8830f / P2M, -20.3727f / P2M),
			b2Vec2(42.3570f / P2M, -16.6886f / P2M),
			b2Vec2(46.7100f / P2M, -3.9623f / P2M),
			b2Vec2(30.3000f / P2M, 19.1457f / P2M),
			b2Vec2(-22.6130f / P2M, 19.8151f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}

void
CEnemyType1::createBoxBodySize3()
{
	b2PolygonShape spriteShape;
	int num = 6;
	b2Vec2 verts[] = {
			b2Vec2(-54.4284f / P2M, -17.2242f / P2M),
			b2Vec2(-11.0256f / P2M, -24.4585f / P2M),
			b2Vec2(50.0592f / P2M, -19.2339f / P2M),
			b2Vec2(56.4900f / P2M, -5.1679f / P2M),
			b2Vec2(35.9940f / P2M, 22.1596f / P2M),
			b2Vec2(-27.1008f / P2M, 23.3654f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}

void
CEnemyType1::createBoxBodySize4()
{
	b2PolygonShape spriteShape;
	int num = 6;
	b2Vec2 verts[] = {
			b2Vec2(-63.7518f / P2M, -21.0019f / P2M),
			b2Vec2(-12.6336f / P2M, -29.2004f / P2M),
			b2Vec2(60.1874f / P2M, -24.3778f / P2M),
			b2Vec2(66.9382f / P2M, -7.0167f / P2M),
			b2Vec2(42.3430f / P2M, 25.2939f / P2M),
			b2Vec2(-31.4412f / P2M, 26.7406f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}
